<html>
	<head>
		<title>Map_Baidu</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
		<style type="text/css">
			body, html {width: 100%;height: 100%; margin:0;font-family:"微软雅黑";}
			#l-map{height:100%;width:100%;}
		</style>

		<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=d6gLzOu82VX0vuc152f3PZ32"></script>
		<script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
	</head>
	<body>
		<div id="l-map"></div>
		
	</body>
</html>

<script type="text/javascript">
	var map = new BMap.Map("l-map");         
	map.centerAndZoom(new BMap.Point(120.222957, 30.215448), 14);

	/**
	 * 搜索地点
	 */
	var search = function(place)
	{
		var local = new BMap.LocalSearch(map, {renderOptions: {map: map}});
		map.clearOverlays();

		local.search(place);
	}

	var transit;// 路由工具
	var time;// 预计时长
	var distance;// 全程距离
	var searchComplete = function(results)
	{
		if (transit.getStatus() != BMAP_STATUS_SUCCESS){
			return ;
		}
		var plan = results.getPlan(0);
		time = plan.getDuration(true);                //获取时间
		distance = plan.getDistance(true);             //获取距离
	}

	/**
	 * 公交路线
	 */
	var routeBus = function(from, to)
	{
		transit = new BMap.TransitRoute(map, {renderOptions: 
														{map: map}, 
														onSearchComplete: searchComplete,
														onPolylinesSet: function(){        
															setTimeout(function(){
																var text = "从 " + from + " 到 " + to +
																"全程距离 " + distance +
																"预计时长 " + time;
																// 回调结果
																window.WebViewActivity.showDriveTimeDistance(text);
															},"500");
														},
														policy: BMAP_TRANSIT_POLICY_LEAST_TIME
													});
		map.clearOverlays();
	
		transit.search(from, to);
	}
	

	/**
	 * 驾车路线
	 */
	var routeDrive = function(from, to)
	{
		transit = new BMap.DrivingRoute(map, {
													renderOptions: 
														{map: map}, 
														onSearchComplete: searchComplete,
														onPolylinesSet: function(){        
															setTimeout(function(){
																var text = "从 " + from + " 到 " + to +
																"全程距离 " + distance +
																"预计时长 " + time;
																// 回调结果
																window.WebViewActivity.showDriveTimeDistance(text);
															},"500");
														},
														policy: BMAP_DRIVING_POLICY_LEAST_TIME
												});
		map.clearOverlays();

		transit.search(from, to);
	}

	


	// 定义一个控件类,即function
	function ZoomControl(){
	  // 默认停靠位置和偏移量
	  this.defaultAnchor = BMAP_ANCHOR_TOP_LEFT;
	  this.defaultOffset = new BMap.Size(10, 10);
	}

	// 通过JavaScript的prototype属性继承于BMap.Control
	ZoomControl.prototype = new BMap.Control();

	var setZoomStyle = function(elt)
	{
		elt.style.cursor = 'pointer';
		elt.style.border = '1px solid gray';
		elt.style.backgroundColor = 'white';
		elt.style.width = '20px';
		elt.style.height = '20px';
		elt.style.textAlign = 'center';
		elt.style.lineHeight = '20px';
		elt.style.position = 'absolute';
	}

	// 自定义控件必须实现自己的initialize方法,并且将控件的DOM元素返回
	// 在本方法中创建个div元素作为控件的容器,并将其添加到地图容器中
	ZoomControl.prototype.initialize = function(map){
	  // 创建一个DOM元素
	  var div = document.createElement("div");
	  var add = document.createElement('span');
	  var sub = document.createElement('span');
	  div.style.width = '100px';
	  div.style.width = '50px';

	  add.appendChild(document.createTextNode('+'));
	  sub.appendChild(document.createTextNode(' -'));
	  // 添加文字说明
	  div.appendChild(add);
	  div.appendChild(sub);
	  // 设置样式
		setZoomStyle(add);
		setZoomStyle(sub);
		sub.style.left = '30px';
	
	  // 绑定事件,点击一次放大两级
	  add.onclick = function(e){
		map.setZoom(map.getZoom() + 1);
	  }
	  sub.onclick = function(e)
		{
			map.setZoom(map.getZoom() - 1);
		}
	  // 添加DOM元素到地图中
	  map.getContainer().appendChild(div);
	  // 将DOM元素返回
	  return div;
	}
	
	// 创建控件
	var myZoomCtrl = new ZoomControl();
	// 添加到地图当中
	map.addControl(myZoomCtrl);

</script>